package api

import (
	"beesoft.ink/application/garage/app/helper"
	"beesoft.ink/application/garage/app/model"
	"beesoft.ink/application/garage/app/service"
	"fmt"
	"github.com/labstack/echo/v4"
)

var Auth auth

type auth struct{}

func (r auth) Login(ctx echo.Context) error {
	var req model.AuthLoginReq
	err := ctx.Bind(&req)
	if err != nil {
		panic(err)
	}
	helper.SetDefaults(&req)

	res, err := service.Auth.Login(ctx, &req)
	if err != nil {
		panic(err)
	}
	return helper.NewResponse(ctx).ResponseOk(res)
}
func (r auth) Logout(ctx echo.Context) error {
	err := service.Auth.Logout(ctx)
	if err != nil {
		panic(err)
	}

	return helper.NewResponse(ctx).ResponseOk()
}
func (r auth) Profile(ctx echo.Context) error {
	item, err := service.Auth.Profile(ctx)
	if err != nil {
		fmt.Println(err)
		//panic(err)
	}

	return helper.NewResponse(ctx).ResponseOk(item)
}
func (r auth) SendVerificationCode(ctx echo.Context) error {
	var req *model.AuthSendVerificationCodeReq
	err := ctx.Bind(&req)

	res, err := service.Auth.SendVerificationCode(ctx, req)
	if err != nil {
		fmt.Println(err)
		//panic(err)
	}

	return helper.NewResponse(ctx).ResponseOk(res)
}
